import { InputQuestion, UploadQuestion, QuestionBase, SelectQuestion, TextQuestion, TimeQuestion } from '@/components/public-template';
import { Api } from '@/config/api/archives';
import { Api as ApiArchives } from '@/config/api/archives';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { Api as ApiFile } from '@/config/api/archivesFile';

class IndexService {
  getQuestions(showType, toDepartment, id) {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'id',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'billId',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'source',
        label: '文件来源',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'ARCHIVES_SOURCE'
        }
      }),
      showType == 'EDIT'
        ? new TextQuestion({
            key: 'name',
            label: '文件名称',
            value: null
          })
        : new SelectQuestion({
            key: 'name',
            label: '文件名称',
            required: true,
            prompt: '请输入',
            value: null,
            type: 'search',
            state: {
              url: ApiFile.findListByFileName,
              protType: 'post',
              nameKey: 'name',
              nameValue: 'id'
            }
          }),
      new TextQuestion({
        key: 'filesBoxCode',
        label: '档案编码',
        value: null
      }),
      new TextQuestion({
        key: 'code',
        label: '文件编码',
        value: null
      }),
      new TextQuestion({
        key: 'fileCode',
        label: '文件号',
        value: null
      }),
      new TextQuestion({
        key: 'type',
        label: '载体形式',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'CARRIER_TYPE'
        }
      }),
      new TextQuestion({
        key: 'filePages',
        label: '文件页数',
        value: null
      }),
      new TextQuestion({
        key: 'filesType',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'filesTypeName',
        label: '档案类型',
        value: null
      }),
      new TextQuestion({
        key: 'eachOther',
        label: '互见号',
        value: null
      }),
      new TextQuestion({
        key: 'chargeUserIdName',
        label: '责任者',
        value: null
      }),
      new TextQuestion({
        key: 'toDepartmentName',
        label: '归档部门',
        value: null
      }),
      new TextQuestion({
        key: 'fromDate',
        label: '形成日期',
        value: null
      }),
      new TimeQuestion({
        key: 'toDate',
        label: '归档日期',
        required: true,
        prompt: '请选择',
        value: null,
        state: {
          valueFormat: 'YYYY-MM-DD'
        },
        type: 'alone'
      }),
      new SelectQuestion({
        key: 'secretLevel',
        label: '保密等级',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new SelectQuestion({
        key: 'retentionPeriodDate',
        label: '保管期限',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_RETENTION_PERIOD_DATE'
        }
      }),
      new SelectQuestion({
        key: 'storageLocation',
        label: '存放地点',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'tree',
        state: {
          fullPath: true,
          url: Api.folderfindCanUseTree,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          initKeys: 'filesBoxId',
          params: {
            name: ''
          }
        }
      }),
      new SelectQuestion({
        key: 'filesBoxId',
        label: '档案盒编码',
        required: true,
        prompt: '请选择',
        value: null,
        state: {
          url: ApiArchives.boxCanUseBox,
          protType: 'post',
          nameKey: 'code',
          nameValue: 'id',
          params: {
            folderId: '',
            typeId: '',
            toDepartment: toDepartment
          }
        }
      }),
      new TextQuestion({
        key: 'boxName',
        label: '档案盒名称',
        value: null
      }),
      new InputQuestion({
        key: 'reelNo',
        label: '卷号',
        disabled: true,
        value: null
      }),
      new InputQuestion({
        key: 'partNo',
        label: '件号',
        required: true,
        prompt: '请输入',
        value: null
      }),
      new InputQuestion({
        key: 'keyword',
        label: '关键字',
        prompt: '请输入',
        value: null
      }),
      new InputQuestion({
        key: 'summary',
        label: '提要',
        prompt: '请输入',
        value: null
      }),
      new UploadQuestion({
        key: 'attachment',
        label: '附件',
        required: true,
        type: 'static',
        prompt: '请上传',
        value: null,
        state: {
          listType: 'text',
          url: ApiResource.resourceUploadFile,
          viewUrl: ApiResource.advancedQueryPreview,
          params: { needRecord: false, previewId: id },
          previewFile: true,
          fieldNames: {
            fileId: 'fileId',
            name: 'name'
          }
        }
      })
    ];
    return questions;
  }
}

export default new IndexService();
